home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dev / ds3100.md / devGraphics.c < prev    next >
C/C++ Source or Header  |  1990-09-11  |  39KB  |  1,750 lines

  1. /* 
  2.  *  devGraphics.c --
  3.  *
  4.  *         This file contains machine-dependent routines for the graphics device.
  5.  *
  6.  *    Copyright (C) 1989 Digital Equipment Corporation.
  7.  *    Permission to use, copy, modify, and distribute this software and
  8.  *    its documentation for any purpose and without fee is hereby granted,
  9.  *    provided that the above copyright notice appears in all copies.  
  10.  *    Digital Equipment Corporation makes no representations about the
  11.  *    suitability of this software for any purpose.  It is provided "as is"
  12.  *    without express or implied warranty.
  13.  */
  14.  
  15. #ifndef lint
  16. static char rcsid[] = "$Header: /sprite/src/kernel/dev/ds3100.md/RCS/devGraphics.c,v 9.6 90/09/11 15:07:42 mendel Exp $ SPRITE (DECWRL)";
  17. #endif not lint
  18.  
  19. #include "sprite.h"
  20. #include "machMon.h"
  21. #include "mach.h"
  22. #include "dev.h"
  23. #include "fs.h"
  24. #include "fsio.h"
  25. #include "sys.h"
  26. #include "sync.h"
  27. #include "timer.h"
  28. #include "dbg.h"
  29. #include "machAddrs.h"
  30. #include "console.h"
  31. #include "dc7085.h"
  32. #include "graphics.h"
  33. #include "vm.h"
  34. #include "vmMach.h"
  35. #include "dev/graphics.h"
  36.  
  37. /*
  38.  * Macro to translate from a time struct to milliseconds.
  39.  */
  40. #define TO_MS(time) ((time.seconds * 1000) + (time.microseconds / 1000))
  41.  
  42. /*
  43.  * System control status register pointer.
  44.  */
  45. static unsigned short    *sysCSRPtr = (unsigned short *)MACH_SYS_CSR_ADDR;
  46.  
  47. /*
  48.  * Pointer to VDAC regs.
  49.  */
  50. static DevVDACRegs    *vdacPtr = (DevVDACRegs *)MACH_VDAC_ADDR;
  51.  
  52. /* 
  53.  * Pointer to the cursor registers.
  54.  */
  55. static DevPCCRegs    *pccPtr = (DevPCCRegs *)MACH_CURSOR_REG_ADDR;
  56.  
  57. static volatile    unsigned short    curReg = 0;    /* Register to keep track of
  58.                          * the pcc command register
  59.                          * bits. */
  60. Boolean    devGraphicsOpen = FALSE;        /* TRUE => the mouse is open.*/
  61.                     /* Process waiting for select.*/
  62. static Boolean    isMono;            /* TRUE */
  63.  
  64. /*
  65.  * These need to mapped into user space.
  66.  */
  67. static DevScreenInfo    scrInfo;
  68. static DevEvent        events[DEV_MAXEVQ] = {0};    
  69. static DevTimeCoord    tcs[MOTION_BUFFER_SIZE] = {0};
  70. static char        *frameBuffer = (char *)MACH_UNCACHED_FRAME_BUFFER_ADDR;
  71. static char        *planeMask = (char *)MACH_PLANE_MASK_ADDR;
  72.  
  73. static unsigned short    cursorBits [32];
  74.  
  75. Boolean            inKBDReset = FALSE;
  76.  
  77. MouseReport        lastRep;
  78. MouseReport        currentRep;
  79.  
  80. static unsigned char bgRgb[3];    /* background and foreground colors     */
  81. static unsigned char fgRgb[3];  /*     for the cursor. */
  82.  
  83. /*
  84.  * Keyboard defaults.
  85.  */
  86. static short divDefaults[15] = { 
  87.     LK_DOWN,    /* 0 doesn't exist */
  88.     LK_AUTODOWN, 
  89.     LK_AUTODOWN, 
  90.     LK_AUTODOWN, 
  91.     LK_DOWN,
  92.     LK_UPDOWN,   
  93.     LK_UPDOWN,   
  94.     LK_AUTODOWN, 
  95.     LK_AUTODOWN, 
  96.     LK_AUTODOWN, 
  97.     LK_AUTODOWN, 
  98.     LK_AUTODOWN, 
  99.     LK_AUTODOWN, 
  100.     LK_DOWN, 
  101.     LK_AUTODOWN 
  102. };
  103.  
  104. /* 
  105.  * Keyboard initialization string.
  106.  */
  107. short kbdInitString[] = {        /* reset any random keyboard stuff */
  108.     LK_AR_ENABLE,            /* we want autorepeat by default */
  109.     LK_CL_ENABLE,            /* keyclick */
  110.     0x84,                /* keyclick volume */
  111.     LK_KBD_ENABLE,            /* the keyboard itself */
  112.     LK_BELL_ENABLE,            /* keyboard bell */
  113.     0x84,                /* bell volume */
  114.     LK_LED_DISABLE,            /* keyboard leds */
  115.     LED_ALL
  116. };
  117.  
  118. #define KBD_INIT_LENGTH    sizeof(kbdInitString) / sizeof(short)
  119.  
  120. /*
  121.  * The default cursor.
  122.  */
  123. unsigned short defCursor[32] = { 
  124. /* plane A */ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,
  125.           0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,
  126. /* plane B */ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,
  127.               0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF
  128.  
  129. };
  130.  
  131. /*
  132.  * Font mask bits used by Blitc().
  133.  */
  134. static unsigned int fontmaskBits[16] = {
  135.     0x00000000,
  136.     0x00000001,
  137.     0x00000100,
  138.     0x00000101,
  139.     0x00010000,
  140.     0x00010001,
  141.     0x00010100,
  142.     0x00010101,
  143.     0x01000000,
  144.     0x01000001,
  145.     0x01000100,
  146.     0x01000101,
  147.     0x01010000,
  148.     0x01010001,
  149.     0x01010100,
  150.     0x01010101
  151. };
  152.  
  153. static Boolean initialized = FALSE;
  154.  
  155. /*
  156.  * Mutex to synchronize access.
  157.  */
  158. Sync_Semaphore graphicsMutex;
  159.  
  160. /*
  161.  * Token used to notify process that has graphics device open that events
  162.  * are available.
  163.  */
  164. ClientData    notifyToken;
  165.  
  166. /*
  167.  * Redefine MASTER_LOCK to be DISABLE_INTR for two reasons.  First, it
  168.  * is more efficient and sufficient on a uni-processor.  Second, MASTER_LOCK
  169.  * can cause deadlock because this file contains the routine which blits
  170.  * a character to the screen.  As a result no routine in here can do a printf
  171.  * underneath the MASTER_LOCK because the Blitc routine grabs the master lock.
  172.  * Once things are debugged and the printfs are removed it should be OK to use
  173.  * a TRUE master lock.
  174.  */
  175. #ifdef MASTER_LOCK
  176. #undef MASTER_LOCK
  177. #undef MASTER_UNLOCK
  178. #endif
  179. #define MASTER_LOCK(mutexPtr)    DISABLE_INTR()
  180. #define MASTER_UNLOCK(mutexPtr)    ENABLE_INTR()
  181.  
  182. /*
  183.  * Forward references.
  184.  */
  185. static void        InitScreenDefaults();
  186. static void        ScreenInit();
  187. static void        LoadCursor();
  188. static void        RestoreCursorColor();
  189. static void        CursorColor();
  190. static void        MouseInit();
  191. static void        KBDReset();
  192. static void        InitColorMap();
  193. static void        VDACInit();
  194. static void        LoadColorMap();
  195. static void         RecvIntr();
  196. static void        MouseEvent();
  197. static void        MouseButtons();
  198. static void        PosCursor();
  199. static void        XmitIntr();
  200. static void        Scroll();
  201. static void        Blitc();
  202.  
  203.  
  204. /*
  205.  * ----------------------------------------------------------------------------
  206.  *
  207.  * DevGraphicsInit --
  208.  *
  209.  *    Initialize the mouse and the screen.
  210.  *
  211.  * Results:
  212.  *    None.
  213.  *
  214.  * Side effects:
  215.  *    The world is initialized.
  216.  *
  217.  * ----------------------------------------------------------------------------
  218.  */
  219. void
  220. DevGraphicsInit()
  221. {
  222.     Time    time;
  223.  
  224.     Sync_SemInitDynamic(&graphicsMutex, "graphicsMutex");
  225.  
  226.     isMono = *sysCSRPtr & MACH_CSR_MONO;
  227.     if (isMono) {
  228.     Mach_MonPrintf("pm0 ( monochrome display )\n");
  229.     } else {
  230.     Mach_MonPrintf("pm0 ( color display )\n");
  231.     }
  232.  
  233.     /*
  234.      * Initialize the screen.
  235.      */
  236.     MACH_DELAY(100000);
  237.     pccPtr->cmdReg = DEV_CURSOR_FOPB | DEV_CURSOR_VBHI;
  238.     /*
  239.      * Initialize the cursor register.
  240.      */
  241.     curReg = DEV_CURSOR_ENPA | DEV_CURSOR_ENPB;
  242.     pccPtr->cmdReg = curReg;
  243.  
  244.     /*
  245.      * Initialize screen info.
  246.      */
  247.     InitScreenDefaults(&scrInfo);
  248.     scrInfo.eventQueue.events = events;
  249.     scrInfo.eventQueue.tcs = tcs;
  250.     scrInfo.bitmap = (char *)MACH_UNCACHED_FRAME_BUFFER_ADDR;
  251.     scrInfo.cursorBits = (short *)(cursorBits);
  252.     Timer_GetRealTimeOfDay(&time, (int *) NIL, (Boolean *) NIL);
  253.     scrInfo.eventQueue.timestampMS = TO_MS(time);
  254.     scrInfo.eventQueue.eSize = DEV_MAXEVQ;
  255.     scrInfo.eventQueue.eHead = scrInfo.eventQueue.eTail = 0;
  256.     scrInfo.eventQueue.tcSize = MOTION_BUFFER_SIZE;
  257.     scrInfo.eventQueue.tcNext = 0;
  258.  
  259.     /*
  260.      * Initialize the color map, the screen, and the mouse.
  261.      */
  262.     InitColorMap();
  263.     ScreenInit();
  264.     MouseInit();
  265.     Scroll();
  266.  
  267.     /*
  268.      * Init the "latest mouse report" structure
  269.      */
  270.     lastRep.state = 0;
  271.     lastRep.dx = 0;
  272.     lastRep.dy = 0;
  273.     lastRep.byteCount = 0;
  274.  
  275.     /*
  276.      * Clear out the cursor.
  277.      */
  278.     if (isMono) { 
  279.     int i;
  280.     for (i = 0; i < 32; i++) {
  281.         scrInfo.cursorBits[i] = 0;
  282.     }
  283.     }
  284.  
  285.     /*
  286.      * Reset the keyboard.
  287.      */
  288.     if(!inKBDReset) {
  289.     KBDReset();
  290.     }
  291.  
  292.     initialized = TRUE;
  293. }    
  294.  
  295.  
  296. /*
  297.  * ----------------------------------------------------------------------------
  298.  *
  299.  * InitScreenDefaults --
  300.  *
  301.  *    Set up default screen parameters.
  302.  *
  303.  * Results:
  304.  *    None.
  305.  *
  306.  * Side effects:
  307.  *    *scrInfoPtr is filled in with default screen parameters.
  308.  *
  309.  * ----------------------------------------------------------------------------
  310.  */
  311. static void
  312. InitScreenDefaults(scrInfoPtr)
  313.     DevScreenInfo    *scrInfoPtr;
  314. {
  315.     bzero((char *)scrInfoPtr, sizeof(DevScreenInfo));
  316.     scrInfoPtr->maxRow = 56;
  317.     scrInfoPtr->maxCol = 80;
  318.     scrInfoPtr->maxX = 1024;
  319.     scrInfoPtr->maxY = 864;
  320.     scrInfoPtr->maxCurX = 1023;
  321.     scrInfoPtr->maxCurY = 863;
  322.     scrInfoPtr->version = 11;
  323.     scrInfoPtr->mthreshold = 4;    
  324.     scrInfoPtr->mscale = 2;
  325.     scrInfoPtr->minCurX = -15;
  326.     scrInfoPtr->minCurY = -15;
  327. }
  328.  
  329.  
  330. /*
  331.  * ----------------------------------------------------------------------------
  332.  *
  333.  * ScreenInit --
  334.  *
  335.  *    Initialize the screen.
  336.  *
  337.  * Results:
  338.  *    None.
  339.  *
  340.  * Side effects:
  341.  *    The screen is initialized.
  342.  *
  343.  * ----------------------------------------------------------------------------
  344.  */
  345. static void
  346. ScreenInit()
  347. {
  348.     /*
  349.      * Home the cursor.
  350.      * We want an LSI terminal emulation.  We want the graphics
  351.      * terminal to scroll from the bottom. So start at the bottom.
  352.      */
  353.     scrInfo.row = 55;
  354.     scrInfo.col = 0;
  355.     
  356.     
  357.     /*
  358.      * Load the cursor with the default values
  359.      *
  360.      */
  361.     LoadCursor(defCursor);
  362.  
  363.     /*
  364.      * Reset keyboard to default state.
  365.      */
  366.      if(!inKBDReset) {
  367.      KBDReset();
  368.      }
  369. }
  370.  
  371.  
  372. /*
  373.  * ----------------------------------------------------------------------------
  374.  *
  375.  * LoadCursor --
  376.  *
  377.  *    Routine to load the cursor Sprite pattern.
  378.  *
  379.  * Results:
  380.  *    None.
  381.  *
  382.  * Side effects:
  383.  *    The cursor is loaded into the hardware cursor.
  384.  *
  385.  * ----------------------------------------------------------------------------
  386.  */
  387. static void
  388. LoadCursor(cur)
  389.     unsigned short *cur;
  390. {
  391.     register int    i;
  392.  
  393.     curReg |= DEV_CURSOR_LODSA;
  394.     pccPtr->cmdReg = curReg;
  395.     for (i = 0; i < 32; i++ ){
  396.     pccPtr->memory = cur[i];
  397.     Mach_EmptyWriteBuffer();
  398.     }
  399.     curReg &= ~DEV_CURSOR_LODSA;
  400.     pccPtr->cmdReg = curReg;
  401. }
  402.  
  403.  
  404. /*
  405.  * ----------------------------------------------------------------------------
  406.  *
  407.  * RestoreCursorColor --
  408.  *
  409.  *    Routine to restore the color of the cursor.
  410.  *
  411.  * Results:
  412.  *    None.
  413.  *
  414.  * Side effects:
  415.  *    None.
  416.  *
  417.  * ----------------------------------------------------------------------------
  418.  */
  419. static void
  420. RestoreCursorColor()
  421. {
  422.     register int i;
  423.  
  424.     vdacPtr->overWA = 0x04;
  425.     Mach_EmptyWriteBuffer();
  426.  
  427.     for (i=0; i < 3; i++) {  
  428.     vdacPtr->over = bgRgb[i];
  429.     Mach_EmptyWriteBuffer();
  430.     }
  431.  
  432.     vdacPtr->overWA = 0x08;
  433.     Mach_EmptyWriteBuffer();
  434.     vdacPtr->over = 0x00;
  435.     Mach_EmptyWriteBuffer();
  436.     vdacPtr->over = 0x00;
  437.     Mach_EmptyWriteBuffer();
  438.     vdacPtr->over = 0x7f;
  439.     Mach_EmptyWriteBuffer();
  440.  
  441.     vdacPtr->overWA = 0x0c;
  442.     Mach_EmptyWriteBuffer();
  443.  
  444.     for (i=0; i < 3; i++) {
  445.     vdacPtr->over = fgRgb[i];
  446.     Mach_EmptyWriteBuffer();
  447.     }
  448. }
  449.  
  450.  
  451. /*
  452.  * ----------------------------------------------------------------------------
  453.  *
  454.  * CursorColor --
  455.  *
  456.  *    Set the color of the cursor.
  457.  *
  458.  * Results:
  459.  *    None.
  460.  *
  461.  * Side effects:
  462.  *    None.
  463.  *
  464.  * ----------------------------------------------------------------------------
  465.  */
  466. static void
  467. CursorColor(color)
  468.     unsigned int color[];
  469. {
  470.     register int i, j;
  471.  
  472.     for (i = 0; i < 3; i++) {
  473.     vdacPtr->over = (unsigned char)(color[i] >> 8);
  474.     bgRgb[i] = (unsigned char )(color[i] >> 8);
  475.     Mach_EmptyWriteBuffer();
  476.     }
  477.  
  478.     for (i = 3, j=0 ; i < 6; i++, j++) {
  479.     vdacPtr->over = (unsigned char)(color[i] >> 8);
  480.     fgRgb[j] = (unsigned char)(color[i] >> 8);
  481.     Mach_EmptyWriteBuffer();
  482.     }
  483.  
  484.     RestoreCursorColor();
  485. }
  486.  
  487.  
  488. /*
  489.  * ----------------------------------------------------------------------------
  490.  *
  491.  * MouseInit --
  492.  *
  493.  *    Initialize the mouse.
  494.  *
  495.  * Results:
  496.  *    None.
  497.  *
  498.  * Side effects:
  499.  *    None.
  500.  *
  501.  * ----------------------------------------------------------------------------
  502.  */
  503. static void
  504. MouseInit()
  505. {
  506.     int    id_byte1, id_byte2, id_byte3, id_byte4;
  507.  
  508.     /*
  509.      * Initialize the mouse.
  510.      */
  511.     DevDC7085MouseInit();
  512.     DevDC7085MousePutCh(MOUSE_SELF_TEST);
  513.     id_byte1 = DevDC7085MouseGetCh();
  514.     if (id_byte1 < 0) {
  515.     printf("MouseInit: Timeout on 1st byte of self-test report\n");
  516.     return;
  517.     }
  518.     id_byte2 = DevDC7085MouseGetCh();
  519.     if (id_byte2 < 0) {
  520.     printf("MouseInit: Timeout on 2nd byte of self-test report\n");
  521.     return;
  522.     }
  523.     id_byte3 = DevDC7085MouseGetCh();
  524.     if (id_byte3 < 0) {
  525.     printf("MouseInit: Timeout on 3rd byte of self-test report\n");
  526.     return;
  527.     }
  528.     id_byte4 = DevDC7085MouseGetCh();
  529.     if (id_byte4 < 0) {
  530.     printf("MouseInit: Timeout on 4th byte of self-test report\n");
  531.     return;
  532.     }
  533.     if ((id_byte2 & 0x0f) != 0x2) {
  534.     printf("MouseInit: We don't have a mouse!!!\n");
  535.     }
  536.     DevDC7085MousePutCh(MOUSE_INCREMENTAL);
  537. }
  538.  
  539.  
  540. /*
  541.  * ----------------------------------------------------------------------------
  542.  *
  543.  * KBDReset --
  544.  *
  545.  *    Reset the keyboard to default characteristics.
  546.  *
  547.  * Results:
  548.  *    None.
  549.  *
  550.  * Side effects:
  551.  *    None.
  552.  *
  553.  * ----------------------------------------------------------------------------
  554.  */
  555. static void
  556. KBDReset()
  557. {
  558.     register int i;
  559.  
  560.     inKBDReset = TRUE;
  561.     DevDC7085KBDPutc(LK_DEFAULTS);
  562.     for (i=1; i < 15; i++) {
  563.     DevDC7085KBDPutc(divDefaults[i] | (i << 3));
  564.     }
  565.     for (i = 0; i < KBD_INIT_LENGTH; i++) {
  566.     DevDC7085KBDPutc ((int)kbdInitString[i]);
  567.     }
  568.     inKBDReset = FALSE;
  569. }
  570.  
  571.  
  572. /*
  573.  * ----------------------------------------------------------------------------
  574.  *
  575.  * InitColorMap --
  576.  *
  577.  *    Initialize the color map.
  578.  *
  579.  * Results:
  580.  *    None.
  581.  *
  582.  * Side effects:
  583.  *    The colormap is initialized appropriately whether it is color or 
  584.  *    monochrome.
  585.  *
  586.  * ----------------------------------------------------------------------------
  587.  */
  588. static void
  589. InitColorMap()
  590. {
  591.     register int i;
  592.  
  593.     *planeMask = 0xff;
  594.     Mach_EmptyWriteBuffer();
  595.  
  596.     VDACInit();
  597.  
  598.     if (isMono) {
  599.         for (i = 0; i < 256; i++) {
  600.         vdacPtr->mapWA = i; Mach_EmptyWriteBuffer();
  601.         vdacPtr->map = (i < 128)? 0x00: 0xff; Mach_EmptyWriteBuffer();
  602.         vdacPtr->map = (i < 128)? 0x00: 0xff; Mach_EmptyWriteBuffer();
  603.         vdacPtr->map = (i < 128)? 0x00: 0xff; Mach_EmptyWriteBuffer();
  604.         }
  605.     } else {
  606.         vdacPtr->mapWA = 0; Mach_EmptyWriteBuffer();
  607.         vdacPtr->map = 0; Mach_EmptyWriteBuffer();
  608.         vdacPtr->map = 0; Mach_EmptyWriteBuffer();
  609.         vdacPtr->map = 0; Mach_EmptyWriteBuffer();
  610.  
  611.         for(i = 1; i < 256; i++) {
  612.             vdacPtr->mapWA = i; Mach_EmptyWriteBuffer();
  613.             vdacPtr->map = 0xff; Mach_EmptyWriteBuffer();
  614.             vdacPtr->map = 0xff; Mach_EmptyWriteBuffer();
  615.             vdacPtr->map = 0xff; Mach_EmptyWriteBuffer();
  616.         }
  617.     }
  618.  
  619.     for (i = 0;i < 3; i++) {
  620.     bgRgb[i] = 0x00;
  621.     fgRgb[i] = 0xff;
  622.     }
  623.  
  624. }
  625.  
  626.  
  627. /*
  628.  * ----------------------------------------------------------------------------
  629.  *
  630.  * VDACInit --
  631.  *
  632.  *    Initialize the VDAC.
  633.  *
  634.  * Results:
  635.  *    None.
  636.  *
  637.  * Side effects:
  638.  *    None.
  639.  *
  640.  * ----------------------------------------------------------------------------
  641.  */
  642. static void
  643. VDACInit()
  644. {
  645.     /*
  646.      *
  647.      * Initialize the VDAC
  648.      */
  649.     vdacPtr->overWA = 0x04;
  650.     Mach_EmptyWriteBuffer();
  651.     vdacPtr->over = 0x00;
  652.     Mach_EmptyWriteBuffer();
  653.     vdacPtr->over = 0x00;
  654.     Mach_EmptyWriteBuffer();
  655.     vdacPtr->over = 0x00;
  656.     Mach_EmptyWriteBuffer();
  657.     vdacPtr->overWA = 0x08;
  658.     Mach_EmptyWriteBuffer();
  659.     vdacPtr->over = 0x00;
  660.     Mach_EmptyWriteBuffer();
  661.     vdacPtr->over = 0x00;
  662.     Mach_EmptyWriteBuffer();
  663.     vdacPtr->over = 0x7f;
  664.     Mach_EmptyWriteBuffer();
  665.     vdacPtr->overWA = 0x0c;
  666.     Mach_EmptyWriteBuffer();
  667.     vdacPtr->over = 0xff;
  668.     Mach_EmptyWriteBuffer();
  669.     vdacPtr->over = 0xff;
  670.     Mach_EmptyWriteBuffer();
  671.     vdacPtr->over = 0xff;
  672.     Mach_EmptyWriteBuffer();
  673.     vdacPtr->mask = 0xff; 
  674.     Mach_EmptyWriteBuffer();
  675.  
  676. }
  677.  
  678.  
  679. /*
  680.  * ----------------------------------------------------------------------------
  681.  *
  682.  * LoadColorMap --
  683.  *
  684.  *    Load the color map.
  685.  *
  686.  * Results:
  687.  *    None.
  688.  *
  689.  * Side effects:
  690.  *    The color map is loaded.
  691.  *
  692.  * ----------------------------------------------------------------------------
  693.  */
  694. static void
  695. LoadColorMap(ptr)
  696.     DevColorMap  *ptr;
  697. {
  698.     if(ptr->index > 256) {
  699.      return;
  700.     }
  701.  
  702.     vdacPtr->mapWA = ptr->index; Mach_EmptyWriteBuffer();
  703.     vdacPtr->map = ptr->entry.red; Mach_EmptyWriteBuffer();
  704.     vdacPtr->map = ptr->entry.green; Mach_EmptyWriteBuffer();
  705.     vdacPtr->map = ptr->entry.blue; Mach_EmptyWriteBuffer();
  706. }
  707.  
  708. static Boolean    consoleCmdDown = FALSE;
  709.  
  710.  
  711. /*
  712.  *----------------------------------------------------------------------
  713.  *
  714.  * DevGraphicsKbdIntr --
  715.  *
  716.  *    Process a received character.
  717.  *
  718.  * Results:
  719.  *    None.
  720.  *
  721.  * Side effects:
  722.  *    Events added to the queue.
  723.  *
  724.  *----------------------------------------------------------------------
  725.  */
  726. void
  727. DevGraphicsKbdIntr(ch)
  728.     unsigned char ch;
  729. {
  730.     int        i;
  731.     Time    time;
  732.     DevEvent    *eventPtr;
  733.     
  734.     if (ch == LK_POWER_ERROR || ch == LK_KDOWN_ERROR ||
  735.     ch == LK_INPUT_ERROR || ch == LK_OUTPUT_ERROR) {
  736.     if(!inKBDReset) {
  737.         printf("\n: RecvIntr: keyboard error,code=%x", ch);
  738.         KBDReset();
  739.     }
  740.     return;
  741.     }
  742.     if (ch < LK_LOWEST) {
  743.        return;
  744.     }
  745.     if (ch == KEY_UP) {
  746.     consoleCmdDown = FALSE;
  747.     } else if (ch == KEY_COMMAND) {
  748.     consoleCmdDown = TRUE;
  749.     } else if (consoleCmdDown) {
  750.     char asciiChar;
  751.  
  752.     consoleCmdDown = FALSE;
  753.     asciiChar = DevDC7085TranslateKey(ch, FALSE, FALSE);
  754.     if (asciiChar != -1) {
  755.         Dev_InvokeConsoleCmd(asciiChar);
  756.         return;
  757.     }
  758.     }
  759.  
  760.     /*
  761.      * See if there is room in the queue.
  762.      */
  763.     i = DEV_EVROUND(scrInfo.eventQueue.eTail + 1);
  764.     if (i == scrInfo.eventQueue.eHead) {
  765.     return;
  766.     }
  767.  
  768.     /*
  769.      * Add the event to the queue.
  770.      */
  771.     eventPtr = &events[scrInfo.eventQueue.eTail];
  772.     eventPtr->type = DEV_BUTTON_RAW_TYPE;
  773.     eventPtr->device = DEV_KEYBOARD_DEVICE;
  774.     eventPtr->x = scrInfo.mouse.x;
  775.     eventPtr->y = scrInfo.mouse.y;
  776.     Timer_GetRealTimeOfDay(&time, (int *) NIL, (Boolean *) NIL);
  777.     eventPtr->time = TO_MS(time);
  778.     eventPtr->key = ch;
  779.     scrInfo.eventQueue.eTail = i;
  780.     dev_LastConsoleInput = time;
  781.     Fsio_DevNotifyReader(notifyToken);
  782. }
  783.  
  784.  
  785. /*
  786.  *----------------------------------------------------------------------
  787.  *
  788.  * DevGraphicsMouseIntr --
  789.  *
  790.  *    Process a received mouse character.
  791.  *
  792.  * Results:
  793.  *    None.
  794.  *
  795.  * Side effects:
  796.  *    Events added to the queue.
  797.  *
  798.  *----------------------------------------------------------------------
  799.  */
  800. void
  801. DevGraphicsMouseIntr(ch)
  802.     unsigned char ch;
  803. {
  804.     MouseReport    *newRepPtr;
  805.  
  806.     newRepPtr = ¤tRep;
  807.     newRepPtr->byteCount++;
  808.     if (ch & MOUSE_START_FRAME) {
  809.     /*
  810.      * The first mouse report byte (button state).
  811.      */
  812.     newRepPtr->state = ch;
  813.     if (newRepPtr->byteCount > 1) {
  814.         newRepPtr->byteCount = 1;
  815.     }
  816.     } else if (newRepPtr->byteCount == 2) {
  817.     /*
  818.      * The second mouse report byte (delta x).
  819.      */
  820.     newRepPtr->dx = ch;
  821.     } else if (newRepPtr->byteCount == 3) {
  822.     /*
  823.      * The final mouse report byte (delta y).
  824.      */
  825.     newRepPtr->dy = ch;
  826.     newRepPtr->byteCount = 0;
  827.     if (newRepPtr->dx != 0 || newRepPtr->dy != 0) {
  828.         /*
  829.          * If the mouse moved, post a motion event.
  830.          */
  831.         MouseEvent(newRepPtr);
  832.     }
  833.     MouseButtons(newRepPtr);
  834.     }
  835. }
  836.  
  837.  
  838. /*
  839.  *----------------------------------------------------------------------
  840.  *
  841.  * MouseEvent --
  842.  *
  843.  *    Process a mouse event.
  844.  *
  845.  * Results:
  846.  *    None.
  847.  *
  848.  * Side effects:
  849.  *    An event is added to the event queue.
  850.  *
  851.  *----------------------------------------------------------------------
  852.  */
  853. static void
  854. MouseEvent(newRepPtr) 
  855.     MouseReport    *newRepPtr;
  856. {
  857.     Time    time;
  858.     unsigned    milliSec;
  859.     int        i;
  860.     DevEvent    *eventPtr;
  861.  
  862.     Timer_GetRealTimeOfDay(&time, (int *) NIL, (Boolean *) NIL);
  863.     milliSec = TO_MS(time);
  864.  
  865.     /*
  866.      * Check to see if we have to accelerate the mouse
  867.      */
  868.     if (scrInfo.mscale >=0) {
  869.     if (newRepPtr->dx >= scrInfo.mthreshold) {
  870.         newRepPtr->dx +=
  871.             (newRepPtr->dx - scrInfo.mthreshold) * scrInfo.mscale;
  872.     }
  873.     if (newRepPtr->dy >= scrInfo.mthreshold) {
  874.         newRepPtr->dy +=
  875.         (newRepPtr->dy - scrInfo.mthreshold) * scrInfo.mscale;
  876.     }
  877.     }
  878.     
  879.     /*
  880.      * Update mouse position
  881.      */
  882.     if( newRepPtr->state & MOUSE_X_SIGN) {
  883.     scrInfo.mouse.x += newRepPtr->dx;
  884.     if (scrInfo.mouse.x > scrInfo.maxCurX) {
  885.         scrInfo.mouse.x = scrInfo.maxCurX;
  886.     }
  887.     } else {
  888.     scrInfo.mouse.x -= newRepPtr->dx;
  889.     if (scrInfo.mouse.x < scrInfo.minCurX) {
  890.         scrInfo.mouse.x = scrInfo.minCurX;
  891.     }
  892.     }
  893.     if( newRepPtr->state & MOUSE_Y_SIGN) {
  894.     scrInfo.mouse.y -= newRepPtr->dy;
  895.     if (scrInfo.mouse.y < scrInfo.minCurY) {
  896.         scrInfo.mouse.y = scrInfo.minCurY;
  897.     }
  898.     } else {
  899.     scrInfo.mouse.y += newRepPtr->dy;
  900.     if (scrInfo.mouse.y > scrInfo.maxCurY) {
  901.         scrInfo.mouse.y = scrInfo.maxCurY;
  902.     }
  903.     }
  904.     if (devGraphicsOpen) {
  905.     /*
  906.      * Move the hardware cursor.
  907.      */
  908.     PosCursor(scrInfo.mouse.x, scrInfo.mouse.y);
  909.     }
  910.     /*
  911.      * Store the motion event in the motion buffer.
  912.      */
  913.     tcs[scrInfo.eventQueue.tcNext].time = milliSec;
  914.     tcs[scrInfo.eventQueue.tcNext].x = scrInfo.mouse.x;
  915.     tcs[scrInfo.eventQueue.tcNext].y = scrInfo.mouse.y;
  916.     scrInfo.eventQueue.tcNext++;
  917.     if (scrInfo.eventQueue.tcNext >= MOTION_BUFFER_SIZE) {
  918.     scrInfo.eventQueue.tcNext = 0;
  919.     }
  920.     if (scrInfo.mouse.y < scrInfo.mbox.bottom &&
  921.     scrInfo.mouse.y >=  scrInfo.mbox.top &&
  922.     scrInfo.mouse.x < scrInfo.mbox.right &&
  923.     scrInfo.mouse.x >=  scrInfo.mbox.left) {
  924.     return;
  925.     }
  926.  
  927.     scrInfo.mbox.bottom = 0;
  928.     if (DEV_EVROUND(scrInfo.eventQueue.eTail + 1) == scrInfo.eventQueue.eHead) {
  929.     return;
  930.     }
  931.  
  932.     i = DEV_EVROUND(scrInfo.eventQueue.eTail -1);
  933.     if ((scrInfo.eventQueue.eTail != scrInfo.eventQueue.eHead) && 
  934.         (i != scrInfo.eventQueue.eHead)) {
  935.     DevEvent    *eventPtr;
  936.     eventPtr = &events[i];
  937.     if(eventPtr->type == DEV_MOTION_TYPE) {
  938.         eventPtr->x = scrInfo.mouse.x;
  939.         eventPtr->y = scrInfo.mouse.y;
  940.         eventPtr->time = milliSec;
  941.         eventPtr->device = DEV_MOUSE_DEVICE;
  942.         return;
  943.     }
  944.     }
  945.     /*
  946.      * Put event into queue and wakeup any waiters.
  947.      */
  948.     eventPtr = &events[scrInfo.eventQueue.eTail];
  949.     eventPtr->type = DEV_MOTION_TYPE;
  950.     eventPtr->time = milliSec;
  951.     eventPtr->x = scrInfo.mouse.x;
  952.     eventPtr->y = scrInfo.mouse.y;
  953.     eventPtr->device = DEV_MOUSE_DEVICE;
  954.     scrInfo.eventQueue.eTail = DEV_EVROUND(scrInfo.eventQueue.eTail + 1);
  955.     dev_LastConsoleInput = time;
  956.     if (devGraphicsOpen) {
  957.     Fsio_DevNotifyReader(notifyToken);
  958.     }
  959. }
  960.  
  961.  
  962. /*
  963.  *----------------------------------------------------------------------
  964.  *
  965.  * MouseButtons --
  966.  *
  967.  *    Process mouse buttons.
  968.  *
  969.  * Results:
  970.  *    None.
  971.  *
  972.  * Side effects:
  973.  *    None.
  974.  *
  975.  *----------------------------------------------------------------------
  976.  */
  977. static void
  978. MouseButtons(newRepPtr)
  979.     MouseReport    *newRepPtr;
  980. {
  981.     static char temp, oldSwitch, newSwitch;
  982.     int        i, j;
  983.     DevEvent    *eventPtr;
  984.     Time    time;
  985.  
  986.     newSwitch = newRepPtr->state & 0x07;
  987.     oldSwitch = lastRep.state & 0x07;
  988.     
  989.     temp = oldSwitch ^ newSwitch;
  990.     if (temp != 0) {
  991.     for (j = 1; j < 8; j <<= 1) {
  992.         if ((j & temp) == 0) {
  993.         continue;
  994.         }
  995.  
  996.         /*
  997.          * Check for room in the queue
  998.          */
  999.         i = DEV_EVROUND(scrInfo.eventQueue.eTail+1);
  1000.         if (i == scrInfo.eventQueue.eHead) {
  1001.         return;
  1002.         }
  1003.  
  1004.         /*
  1005.          * Put event into queue.
  1006.          */
  1007.         eventPtr = &events[scrInfo.eventQueue.eTail];
  1008.     
  1009.         switch (j) {
  1010.         case RIGHT_BUTTON:
  1011.             eventPtr->key = DEV_EVENT_RIGHT_BUTTON;
  1012.             break;
  1013.         case MIDDLE_BUTTON:
  1014.             eventPtr->key = DEV_EVENT_MIDDLE_BUTTON;
  1015.             break;
  1016.         case LEFT_BUTTON:
  1017.             eventPtr->key = DEV_EVENT_LEFT_BUTTON;
  1018.             break;
  1019.         }
  1020.         if (newSwitch & j) {
  1021.         eventPtr->type = DEV_BUTTON_DOWN_TYPE;
  1022.         } else {
  1023.         eventPtr->type = DEV_BUTTON_UP_TYPE;
  1024.         }
  1025.         eventPtr->device = DEV_MOUSE_DEVICE;
  1026.  
  1027.         Timer_GetRealTimeOfDay(&time, (int *) NIL, (Boolean *) NIL);
  1028.         eventPtr->time = TO_MS(time);
  1029.         eventPtr->x = scrInfo.mouse.x;
  1030.         eventPtr->y = scrInfo.mouse.y;
  1031.     }
  1032.     scrInfo.eventQueue.eTail = i;
  1033.     if (devGraphicsOpen) {
  1034.         Fsio_DevNotifyReader(notifyToken);
  1035.     }
  1036.  
  1037.     /* 
  1038.      * Update the last report 
  1039.      */
  1040.     lastRep = currentRep;
  1041.     scrInfo.mswitches = newSwitch;
  1042.     }
  1043. }
  1044.  
  1045.  
  1046. /*
  1047.  *----------------------------------------------------------------------
  1048.  *
  1049.  * PosCursor --
  1050.  *
  1051.  *    Postion the cursor.
  1052.  *
  1053.  * Results:
  1054.  *    None.
  1055.  *
  1056.  * Side effects:
  1057.  *    None.
  1058.  *
  1059.  *----------------------------------------------------------------------
  1060.  */
  1061. static void
  1062. PosCursor(x, y)
  1063.     register int x,y;
  1064. {
  1065.     if( y < scrInfo.minCurY || y > scrInfo.maxCurY ) {
  1066.     y = scrInfo.maxCurY;
  1067.     }
  1068.     if(x < scrInfo.minCurX || x > scrInfo.maxCurX) {
  1069.     x = scrInfo.maxCurX;
  1070.     }
  1071.     scrInfo.cursor.x = x;        /* keep track of real cursor*/
  1072.     scrInfo.cursor.y = y;        /* position, indep. of mouse*/
  1073.     pccPtr->xPos = MOUSE_X_OFFSET + x;
  1074.     pccPtr->yPos = MOUSE_Y_OFFSET + y;
  1075. }
  1076.  
  1077.  
  1078. /*
  1079.  *----------------------------------------------------------------------
  1080.  *
  1081.  * Scroll --
  1082.  *
  1083.  *    Scroll the screen.
  1084.  *
  1085.  * Results:
  1086.  *    None.
  1087.  *
  1088.  * Side effects:
  1089.  *    None.
  1090.  *
  1091.  *----------------------------------------------------------------------
  1092.  */
  1093. static void
  1094. Scroll()
  1095. {
  1096.     int    line;
  1097.     register int *dest, *src;
  1098.     register int *end;
  1099.     register int temp0,temp1,temp2,temp3;
  1100.     register int i, scanInc, lineCount;
  1101.  
  1102. #ifdef notdef
  1103.     /*
  1104.      * If the mouse is on we don't scroll so that the bit map remains sane.
  1105.      */
  1106.     if(devGraphicsOpen) {
  1107.     scrInfo.row = 0;
  1108.     return;
  1109.     }
  1110. #endif
  1111.  
  1112.     /*
  1113.      *  The following is an optimization to cause the scrolling 
  1114.      *  of text to be memory limited.  Basically the writebuffer is 
  1115.      *  4 words (32 bits ea.) long so to achieve maximum speed we 
  1116.      *  read and write in multiples of 4 words. We also limit the 
  1117.      *  size to be 80 characters for more speed. 
  1118.      */
  1119.     if(isMono) {
  1120.     lineCount = 5;
  1121.     line = 1920 * 2;
  1122.     scanInc = 44;
  1123.     } else {
  1124.     lineCount = 40;
  1125.     scanInc = 96;
  1126.     line = 1920 * 8;
  1127.     }
  1128.     src = (int *)(frameBuffer+line);
  1129.     dest = (int *)(frameBuffer);
  1130.     end = (int *)(frameBuffer+ (60 * line) - line);
  1131.     do {
  1132.     i = 0;
  1133.     do {
  1134.         temp0 = src[0];
  1135.         temp1 = src[1];
  1136.         temp2 = src[2];
  1137.         temp3 = src[3];
  1138.         dest[0] = temp0;
  1139.         dest[1] = temp1;
  1140.         dest[2] = temp2;
  1141.         dest[3] = temp3;
  1142.         dest += 4;
  1143.         src += 4;
  1144.         i++;
  1145.     } while(i < lineCount);
  1146.     src += scanInc;
  1147.     dest += scanInc;
  1148.     } while(src < end);
  1149.  
  1150.     /* 
  1151.      * Now zero out the last two lines 
  1152.      */
  1153.     bzero(frameBuffer+(scrInfo.row * line),  3 * line);
  1154. }
  1155.  
  1156.  
  1157. /*
  1158.  *----------------------------------------------------------------------
  1159.  *
  1160.  * Dev_GraphicsPutc --
  1161.  *
  1162.  *    Write a character to the console.
  1163.  *
  1164.  * Results:
  1165.  *    None.
  1166.  *
  1167.  * Side effects:
  1168.  *    None.
  1169.  *
  1170.  *----------------------------------------------------------------------
  1171.  */
  1172. int 
  1173. Dev_GraphicsPutc(c)
  1174. register char c;
  1175. {
  1176.     MASTER_LOCK(&graphicsMutex);
  1177.  
  1178.     if (initialized) {
  1179.     Blitc((unsigned char)(c & 0xff));
  1180.     } else {
  1181.     if (isascii(c)) {
  1182.         mach_MonFuncs.mputchar(c);
  1183.     }
  1184.     }
  1185.  
  1186.     MASTER_UNLOCK(&graphicsMutex);
  1187.  
  1188.     return(1);
  1189. }
  1190.  
  1191.  
  1192. /*
  1193.  *----------------------------------------------------------------------
  1194.  *
  1195.  * Blitc --
  1196.  *
  1197.  *    Write a character to the screen.
  1198.  *
  1199.  * Results:
  1200.  *    None.
  1201.  *
  1202.  * Side effects:
  1203.  *    None.
  1204.  *
  1205.  *----------------------------------------------------------------------
  1206.  */
  1207. static void
  1208. Blitc(c)
  1209.     register unsigned char c;
  1210. {
  1211.     register char *bRow, *fRow;
  1212.     register int i;
  1213.     register int ote = isMono ? 256 : 1024; /* offset to table entry */
  1214.     int colMult = isMono ? 1 : 8;
  1215.     extern char devFont[];
  1216.  
  1217.     c &= 0xff;
  1218.  
  1219.     switch ( c ) {
  1220.     case '\t':
  1221.         for(i = 8 - (scrInfo.col & 0x7); i > 0; i--) {
  1222.         Blitc(' ');
  1223.         }
  1224.         break;
  1225.     case '\r':
  1226.         scrInfo.col = 0;
  1227.         break;
  1228.     case '\b':
  1229.         scrInfo.col--;
  1230.         if(scrInfo.col < 0) {
  1231.         scrInfo.col = 0;
  1232.         }
  1233.         break;
  1234.     case '\n':
  1235.         if(scrInfo.row + 1 >= scrInfo.maxRow) {
  1236.         Scroll();
  1237.         } else {
  1238.         scrInfo.row++;
  1239.         }
  1240.         scrInfo.col = 0;
  1241.         break;
  1242.     case '\007':
  1243.         DevDC7085KBDPutc(LK_RING_BELL);
  1244.         break;
  1245.     default:
  1246.         /*
  1247.          * If the next character will wrap around then 
  1248.          * increment row counter or scroll screen.
  1249.          */
  1250.         if (scrInfo.col >= scrInfo.maxCol) {
  1251.         scrInfo.col = 0;
  1252.         if(scrInfo.row + 1 >= scrInfo.maxRow) {
  1253.             Scroll();
  1254.         } else {
  1255.             scrInfo.row++;
  1256.         }
  1257.         }
  1258.         /*
  1259.          * xA1 to XFD are the printable characters added with 8-bit
  1260.          * support.
  1261.          */
  1262.         if ((c >= ' ' && c <= '~') || (c >= 0xA1 && c <= 0xFD)) {
  1263.         bRow = frameBuffer + (scrInfo.row * 15 & 0x3ff) * ote + 
  1264.                scrInfo.col * colMult;
  1265.         i = c - ' ';
  1266.         if(i < 0 || i > 221) {
  1267.             i = 0;
  1268.         } else {
  1269.             /* These are to skip the (32) 8-bit 
  1270.              * control chars, as well as DEL 
  1271.              * and 0xA0 which aren't printable */
  1272.             if (c > '~') {
  1273.             i -= 34; 
  1274.             }
  1275.             i *= 15;
  1276.         }
  1277.         fRow = (char *)((int)devFont + i);
  1278.  
  1279.         /* inline expansion for speed */
  1280.         if(isMono) {
  1281.             *bRow = *fRow++; bRow += ote;
  1282.             *bRow = *fRow++; bRow += ote;
  1283.             *bRow = *fRow++; bRow += ote;
  1284.             *bRow = *fRow++; bRow += ote;
  1285.             *bRow = *fRow++; bRow += ote;
  1286.             *bRow = *fRow++; bRow += ote;
  1287.             *bRow = *fRow++; bRow += ote;
  1288.             *bRow = *fRow++; bRow += ote;
  1289.             *bRow = *fRow++; bRow += ote;
  1290.             *bRow = *fRow++; bRow += ote;
  1291.             *bRow = *fRow++; bRow += ote;
  1292.             *bRow = *fRow++; bRow += ote;
  1293.             *bRow = *fRow++; bRow += ote;
  1294.             *bRow = *fRow++; bRow += ote;
  1295.             *bRow = *fRow++; bRow += ote;
  1296.         } else {
  1297.             int j;
  1298.             unsigned int *pInt;
  1299.  
  1300.             pInt = (unsigned int *) bRow;
  1301.             for(j = 0; j < 15; j++) {
  1302.             /*
  1303.              * fontmaskBits converts a nibble
  1304.              * (4 bytes) to a long word 
  1305.              * containing 4 pixels corresponding
  1306.              * to each bit in the nibble.  Thus
  1307.              * we write two longwords for each
  1308.              * byte in font.
  1309.              * 
  1310.              * Remember the font is 8 bits wide
  1311.              * and 15 bits high.
  1312.              *
  1313.              * We add 256 to the pointer to
  1314.              * point to the pixel on the 
  1315.              * next scan line
  1316.              * directly below the current
  1317.              * pixel.
  1318.              */
  1319.             *pInt =  fontmaskBits[(*fRow)&0xf];
  1320.             *(pInt+1)= fontmaskBits[((*fRow)>>4)&0xf];
  1321.             fRow++; 
  1322.             pInt += 256;
  1323.             }
  1324.         }
  1325.         scrInfo.col++; /* increment column counter */
  1326.     }
  1327.     }
  1328.     if (!devGraphicsOpen) {
  1329.     PosCursor(scrInfo.col * 8, scrInfo.row * 15);
  1330.     }
  1331. }
  1332.  
  1333.  
  1334. /*
  1335.  *----------------------------------------------------------------------
  1336.  *
  1337.  * DevGraphicsOpen --
  1338.  *
  1339.  *    Open the graphics device.
  1340.  *
  1341.  * Results:
  1342.  *    None.
  1343.  *
  1344.  * Side effects:
  1345.  *    None.
  1346.  *
  1347.  *----------------------------------------------------------------------
  1348.  */
  1349. /*ARGSUSED*/
  1350. ReturnStatus
  1351. DevGraphicsOpen(devicePtr, useFlags, inNotifyToken, flagsPtr)
  1352.     Fs_Device *devicePtr;    /* Specifies type and unit number. */
  1353.     int useFlags;        /* Flags from the stream being opened */
  1354.     ClientData inNotifyToken;    /* Used for Fs call-back to notify waiting
  1355.                  * processes that the console device is ready.*/
  1356.     int        *flagsPtr;    /* Device open flags. */
  1357. {
  1358.     Time    time;
  1359.  
  1360.     MASTER_LOCK(&graphicsMutex);
  1361.  
  1362.     if (devicePtr->unit == DEV_MOUSE_UNIT) {
  1363.     if (devGraphicsOpen) {
  1364.         MASTER_UNLOCK(&graphicsMutex);
  1365.         return(FS_FILE_BUSY);
  1366.     }
  1367.     devGraphicsOpen = TRUE;
  1368.     devDivertXInput = FALSE;
  1369.     notifyToken = inNotifyToken;
  1370.     if (!isMono) {
  1371.         InitColorMap();
  1372.     }
  1373.     /*
  1374.      * Set up event queue for later
  1375.      */
  1376.     scrInfo.eventQueue.events = events;
  1377.     scrInfo.eventQueue.tcs = tcs;
  1378.     scrInfo.bitmap = (char *)(MACH_UNCACHED_FRAME_BUFFER_ADDR);
  1379.     scrInfo.cursorBits = (short *)(cursorBits);
  1380.     scrInfo.eventQueue.eSize = DEV_MAXEVQ;
  1381.     scrInfo.eventQueue.eHead = scrInfo.eventQueue.eTail = 0;
  1382.     scrInfo.eventQueue.tcSize = MOTION_BUFFER_SIZE;
  1383.     scrInfo.eventQueue.tcNext = 0;
  1384.     Timer_GetRealTimeOfDay(&time, (int *) NIL, (Boolean *) NIL);
  1385.     scrInfo.eventQueue.timestampMS = TO_MS(time);
  1386.     }
  1387.     MASTER_UNLOCK(&graphicsMutex);
  1388.     return(SUCCESS);
  1389. }
  1390.  
  1391.  
  1392. /*
  1393.  *----------------------------------------------------------------------
  1394.  *
  1395.  * DevGraphicsClose --
  1396.  *
  1397.  *    Close the graphics device.
  1398.  *
  1399.  * Results:
  1400.  *    None.
  1401.  *
  1402.  * Side effects:
  1403.  *    None.
  1404.  *
  1405.  *----------------------------------------------------------------------
  1406.  */
  1407. /*ARGSUSED*/
  1408. ReturnStatus
  1409. DevGraphicsClose(devicePtr, useFlags, openCount, writerCount)
  1410.     Fs_Device    *devicePtr;    /* Device information. */
  1411.     int        useFlags;    /* FS_READ | FS_WRITE */
  1412.     int        openCount;    /* Number of times still open. */
  1413.     int        writerCount;    /* Number of times still open for writing. */
  1414. {
  1415.     MASTER_LOCK(&graphicsMutex);
  1416.  
  1417.     if (devicePtr->unit == DEV_MOUSE_UNIT) {
  1418.     if (!devGraphicsOpen) {
  1419.         MASTER_UNLOCK(&graphicsMutex);
  1420.         return(FS_FILE_BUSY);
  1421.     }
  1422.     devGraphicsOpen = FALSE;
  1423.     if (!isMono) {
  1424.         InitColorMap();
  1425.     }
  1426.     ScreenInit();
  1427.     VmMach_UserUnmap();
  1428.     }
  1429.     MASTER_UNLOCK(&graphicsMutex);
  1430.     return(SUCCESS);
  1431. }
  1432.  
  1433.  
  1434. /*
  1435.  *----------------------------------------------------------------------
  1436.  *
  1437.  * DevGraphicsRead --
  1438.  *
  1439.  *    Read from the graphics device.
  1440.  *
  1441.  * Results:
  1442.  *    None.
  1443.  *
  1444.  * Side effects:
  1445.  *    None.
  1446.  *
  1447.  *----------------------------------------------------------------------
  1448.  */
  1449. /*ARGSUSED*/
  1450. ReturnStatus
  1451. DevGraphicsRead(devicePtr, readPtr, replyPtr)
  1452.     Fs_Device    *devicePtr;    /* Device to read from */
  1453.     Fs_IOParam    *readPtr;    /* Read parameter block */
  1454.     Fs_IOReply    *replyPtr;    /* Return length and signal */ 
  1455. {
  1456. }
  1457.  
  1458.  
  1459. /*
  1460.  *----------------------------------------------------------------------
  1461.  *
  1462.  * DevGraphicsWrite --
  1463.  *
  1464.  *    Write to the graphics device.
  1465.  *
  1466.  * Results:
  1467.  *    None.
  1468.  *
  1469.  * Side effects:
  1470.  *    None.
  1471.  *
  1472.  *----------------------------------------------------------------------
  1473.  */
  1474. /*ARGSUSED*/
  1475. ReturnStatus
  1476. DevGraphicsWrite(devicePtr, writePtr, replyPtr)
  1477.     Fs_Device    *devicePtr;    /* Indicates device */    
  1478.     Fs_IOParam    *writePtr;    /* Standard write parameter block */
  1479.     Fs_IOReply    *replyPtr;    /* Return length and signal */
  1480. {
  1481. }
  1482.  
  1483.  
  1484. /*
  1485.  *----------------------------------------------------------------------
  1486.  *
  1487.  * DevGraphicsIOControl --
  1488.  *
  1489.  *    Perform an io control on the graphics device.
  1490.  *
  1491.  * Results:
  1492.  *    None.
  1493.  *
  1494.  * Side effects:
  1495.  *    None.
  1496.  *
  1497.  *----------------------------------------------------------------------
  1498.  */
  1499. /*ARGSUSED*/
  1500. ReturnStatus
  1501. DevGraphicsIOControl(devicePtr, ioctlPtr, replyPtr)
  1502.     Fs_Device        *devicePtr;
  1503.     Fs_IOCParam        *ioctlPtr;
  1504.     Fs_IOReply        *replyPtr;
  1505. {
  1506.     ReturnStatus status = SUCCESS;
  1507.     int        isColor;
  1508.  
  1509.     MASTER_LOCK(&graphicsMutex);
  1510.  
  1511.     switch (ioctlPtr->command) {
  1512.     case IOC_GRAPHICS_GET_INFO: {
  1513.         Address        addr;
  1514.  
  1515.         /*
  1516.          * Map the screen info struct into the user's address space.
  1517.          */
  1518.         addr = VmMach_UserMap(sizeof(scrInfo), (Address)&scrInfo, TRUE);
  1519.         if (addr == (Address)NIL) {
  1520.         goto mapError;
  1521.         }
  1522.         bcopy((char *)&addr, ioctlPtr->outBuffer, sizeof(addr));
  1523.         /*
  1524.          * Map the events into the user's address space.
  1525.          */
  1526.         addr = VmMach_UserMap(sizeof(events), (Address)events, FALSE);
  1527.         if (addr == (Address)NIL) {
  1528.         goto mapError;
  1529.         }
  1530.         scrInfo.eventQueue.events = (DevEvent *)addr;
  1531.         /*
  1532.          * Map the tcs into the user's address space.
  1533.          */
  1534.         addr = VmMach_UserMap(sizeof(tcs), (Address)tcs, FALSE);
  1535.         if (addr == (Address)NIL) {
  1536.         goto mapError;
  1537.         }
  1538.         scrInfo.eventQueue.tcs = (DevTimeCoord *)addr;
  1539.         /*
  1540.          * Map the plane mask into the user's address space.
  1541.          */
  1542.         addr = VmMach_UserMap(4, (Address)MACH_PLANE_MASK_ADDR, FALSE);
  1543.         if (addr == (Address)NIL) {
  1544.         goto mapError;
  1545.         }
  1546.         scrInfo.planeMask = (char *)addr;
  1547.         /*
  1548.          * Map the bitmap into the user's address space.
  1549.          */
  1550.         addr = VmMach_UserMap(isMono ? 256*1024 : 1024*1024,
  1551.                   (Address)MACH_UNCACHED_FRAME_BUFFER_ADDR, FALSE);
  1552.         if (addr == (Address)NIL) {
  1553.         goto mapError;
  1554.         }
  1555.         scrInfo.bitmap = (char *)addr;
  1556.         break;
  1557. mapError:    
  1558.         VmMach_UserUnmap();
  1559.         status = FS_BUFFER_TOO_BIG;
  1560.         printf("Cannot map shared data structures\n");
  1561.         break;
  1562.     }
  1563.  
  1564.     case IOC_GRAPHICS_MOUSE_POS:
  1565.         /*
  1566.          * Set mouse state.
  1567.          */
  1568.         scrInfo.mouse = *((DevCursor *)ioctlPtr->inBuffer);
  1569.         PosCursor(scrInfo.mouse.x, scrInfo.mouse.y );
  1570.         break;
  1571.  
  1572.     case IOC_GRAPHICS_INIT_SCREEN:    
  1573.         /*
  1574.          * Initialize the screen.
  1575.          */
  1576.         ScreenInit();
  1577.         break;
  1578.  
  1579.     case IOC_GRAPHICS_KBD_CMD: {
  1580.         DevKpCmd        *kpCmdPtr;
  1581.         unsigned char    *cp;
  1582.  
  1583.         kpCmdPtr = (DevKpCmd *)ioctlPtr->inBuffer;
  1584.         if (kpCmdPtr->nbytes == 0) {
  1585.         kpCmdPtr->cmd |= 0x80;
  1586.         }
  1587.         if (!devGraphicsOpen) {
  1588.         kpCmdPtr->cmd |= 1;
  1589.         }
  1590.         DevDC7085KBDPutc((int)kpCmdPtr->cmd);
  1591.         cp = &kpCmdPtr->par[0];
  1592.         for (cp = &kpCmdPtr->par[0]; 
  1593.              kpCmdPtr->nbytes > 0;
  1594.          cp++, kpCmdPtr->nbytes--) {
  1595.         if(kpCmdPtr->nbytes == 1) {
  1596.             *cp |= 0x80;
  1597.         }
  1598.         DevDC7085KBDPutc((int)*cp);
  1599.         }
  1600.         break;
  1601.     }
  1602.  
  1603.     case IOC_GRAPHICS_GET_INFO_ADDR:    
  1604.         *(DevScreenInfo **)ioctlPtr->outBuffer = &scrInfo;
  1605.         break;
  1606.  
  1607.     case IOC_GRAPHICS_CURSOR_BIT_MAP:
  1608.         LoadCursor((unsigned short *)ioctlPtr->inBuffer);
  1609.         break;
  1610.  
  1611.     case IOC_GRAPHICS_CURSOR_COLOR:
  1612.         CursorColor((unsigned int *)ioctlPtr->inBuffer);
  1613.         break;
  1614.          
  1615.         case IOC_GRAPHICS_COLOR_MAP:
  1616.         LoadColorMap((DevColorMap *)ioctlPtr->inBuffer);
  1617.         break;
  1618.  
  1619.     case IOC_GRAPHICS_KERN_LOOP: 
  1620.         printf("DevGraphicsIOControl: QIOKERNLOOP\n");
  1621.         break;
  1622.  
  1623.     case IOC_GRAPHICS_KERN_UNLOOP: 
  1624.         printf("DevGraphicsIOControl: QIOKERNUNLOOP\n");
  1625.         break;
  1626.  
  1627.     case IOC_GRAPHICS_VIDEO_ON:
  1628.         if (!isMono) {
  1629.         RestoreCursorColor();
  1630.         }
  1631.         curReg |= (DEV_CURSOR_ENPA);
  1632.         curReg &= ~(DEV_CURSOR_FOPB);
  1633.         pccPtr->cmdReg = curReg;
  1634.         break;
  1635.  
  1636.     case IOC_GRAPHICS_VIDEO_OFF:
  1637.         if (!isMono) {
  1638.         VDACInit();
  1639.         }
  1640.         curReg |= DEV_CURSOR_FOPB;
  1641.         curReg &= ~(DEV_CURSOR_ENPA);
  1642.         pccPtr->cmdReg = curReg;
  1643.         break;
  1644.     case    IOC_GET_FLAGS:
  1645.     case    IOC_SET_FLAGS:
  1646.     case    IOC_SET_BITS:
  1647.     case    IOC_CLEAR_BITS:
  1648.         /*
  1649.          * No graphics specific bits are set this way.
  1650.          */
  1651.         break;
  1652.     case IOC_GRAPHICS_IS_COLOR:
  1653.         isColor = ! (*sysCSRPtr & MACH_CSR_MONO);
  1654.         bcopy((char *)&isColor, ioctlPtr->outBuffer, sizeof (int));
  1655.         break;
  1656.  
  1657.     default:
  1658.         printf("DevGraphicsIOControl: Unknown command %d\n", 
  1659.            ioctlPtr->command);
  1660.         status = FS_INVALID_ARG;
  1661.         break;
  1662.     }
  1663.  
  1664.     MASTER_UNLOCK(&graphicsMutex);
  1665.     return(status);
  1666. }
  1667.  
  1668.  
  1669. /*
  1670.  *----------------------------------------------------------------------
  1671.  *
  1672.  * DevGraphicsSelect --
  1673.  *
  1674.  *    Perform a select on the graphics device.
  1675.  *
  1676.  * Results:
  1677.  *    None.
  1678.  *
  1679.  * Side effects:
  1680.  *    None.
  1681.  *
  1682.  *----------------------------------------------------------------------
  1683.  */
  1684. ReturnStatus
  1685. DevGraphicsSelect(devicePtr, readPtr, writePtr, exceptPtr)
  1686.     Fs_Device            *devicePtr;
  1687.     int            *readPtr;
  1688.     int            *writePtr;
  1689.     int            *exceptPtr;
  1690. {
  1691.     ReturnStatus status = SUCCESS;
  1692.  
  1693.     MASTER_LOCK(&graphicsMutex);
  1694.  
  1695.     if (*readPtr) {
  1696.     if (devicePtr->unit == DEV_MOUSE_UNIT) {
  1697.         if (scrInfo.eventQueue.eHead == scrInfo.eventQueue.eTail) {
  1698.         *readPtr = 0;
  1699.         }
  1700.     } else {
  1701.         *readPtr = 0;
  1702.     }
  1703.     }
  1704.  
  1705.     MASTER_UNLOCK(&graphicsMutex);
  1706.  
  1707.     *writePtr = *exceptPtr = 0;
  1708.  
  1709.     return(status);
  1710. }
  1711.  
  1712.  
  1713.  
  1714. /*
  1715.  *----------------------------------------------------------------------
  1716.  *
  1717.  * Dev_VidEnable --
  1718.  *
  1719.  *    Enables or disables the video display.
  1720.  *
  1721.  * Results:
  1722.  *    None.
  1723.  *
  1724.  * Side effects:
  1725.  *    Turns video on or off.
  1726.  *
  1727.  *----------------------------------------------------------------------
  1728.  */
  1729. ReturnStatus
  1730. Dev_VidEnable(onOff)
  1731. Boolean onOff;        /* TRUE if video is to be on. */
  1732. {
  1733.     if (onOff) {
  1734.     if (!isMono) {
  1735.         RestoreCursorColor();
  1736.     }
  1737.     curReg |= (DEV_CURSOR_ENPA);
  1738.     curReg &= ~(DEV_CURSOR_FOPB);
  1739.     pccPtr->cmdReg = curReg;
  1740.     } else {
  1741.     if (!isMono) {
  1742.         VDACInit();
  1743.     }
  1744.     curReg |= DEV_CURSOR_FOPB;
  1745.     curReg &= ~(DEV_CURSOR_ENPA);
  1746.     pccPtr->cmdReg = curReg;
  1747.     }
  1748.     return(SUCCESS);
  1749. }
  1750.